//
//  DetailOfPhotographTableViewCell.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/15.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "DetailOfPhotographTableViewCell.h"
#import "LuBDefine.h"
#import "StoryViewController.h"

#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation DetailOfPhotographTableViewCell

- (void)dealloc{
    [_detailOfPhotograph release];
    [_avatarImageView release];
    [_cityLabel release];
    [_groupsLabel release];
    [_nicknameLabel release];
    [_tagsLabel release];
    [_ageLabel release];
    [_birthLabel release];
    [_fnumButton release];
    [_petnameLabel release];
    [_photoImageView release];
    [_picnumButton release];
    [_storynumButton release];
    [_type_nameLabel release];
    [_birth2Label release];
    [_zanLabel release];
    [_bgImageView release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createDetailOfPhotographViewCell];
    }
    return self;
}

- (void)createDetailOfPhotographViewCell{
    
    self.selectionStyle = 0;
    
    self.bgImageView = [[UIImageView alloc]init];
    self.bgImageView.image = [UIImage imageNamed:@"2.jpg"];
    self.bgImageView.alpha= 0.85;
    self.bgImageView.userInteractionEnabled = YES;
    [self.contentView addSubview:_bgImageView];
    [_bgImageView release];
    
    self.photoImageView = [[UIImageView alloc]init];
    self.photoImageView.layer.shadowOffset = CGSizeMake(10, 10);
    self.photoImageView.layer.shadowColor = [[UIColor blackColor] CGColor];
    self.photoImageView.layer.shadowOpacity = 1;
    self.photoImageView.layer.borderColor = [[UIColor whiteColor]CGColor];
    self.photoImageView.layer.borderWidth = 3;
    [self.bgImageView addSubview:_photoImageView];
    [_photoImageView release];
    
    self.nicknameLabel = [[UILabel alloc]init];
    self.nicknameLabel.backgroundColor = [UIColor clearColor];
    self.nicknameLabel.textColor = [UIColor whiteColor];
    [self.bgImageView addSubview:_nicknameLabel];
    [_nicknameLabel release];
    
    self.groupsLabel = [[UILabel alloc]init];
    self.groupsLabel.textColor = [UIColor whiteColor];
    [self.bgImageView addSubview:_groupsLabel];
    [_groupsLabel release];
    
    self.avatarImageView = [[UIImageView alloc]init];
    self.avatarImageView.layer.shadowOffset = CGSizeMake(10, 10);
    self.avatarImageView.layer.shadowColor = [[UIColor blackColor] CGColor];
    self.avatarImageView.layer.shadowOpacity = 1;
    self.avatarImageView.layer.borderColor = [[UIColor whiteColor]CGColor];
    self.avatarImageView.layer.borderWidth = 2;
    [self.bgImageView addSubview:_avatarImageView];
    [_avatarImageView release];
    
    self.petnameLabel = [[UILabel alloc]init];
    [self.bgImageView addSubview:_petnameLabel];
    [_petnameLabel release];
    
    self.birthLabel = [[UILabel alloc]init];
    [self.bgImageView addSubview:_birthLabel];
    [_birthLabel release];
    
    self.picnumButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.picnumButton.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];
    [self.picnumButton addTarget:self action:@selector(picnumButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgImageView addSubview:_picnumButton];
//    [_picnumButton release];
    
    self.storynumButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.storynumButton.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];
    [self.storynumButton addTarget:self action:@selector(storynumButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgImageView addSubview:_storynumButton];
//    [_storynumButton release];
    
    self.fnumButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.fnumButton.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];
    [self.fnumButton addTarget:self action:@selector(fnumButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgImageView addSubview:_fnumButton];
//    [_fnumButton release];
    
    self.zanLabel = [[UILabel alloc]init];
    self.zanLabel.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];
    [self.bgImageView addSubview:_zanLabel];
    self.zanLabel.textColor = [UIColor whiteColor];
    [_zanLabel release];
    
    self.type_nameLabel = [[UILabel alloc]init];
    [self.bgImageView addSubview:_type_nameLabel];
    [_type_nameLabel release];
    
    self.birth2Label = [[UILabel alloc]init];
    [self.bgImageView addSubview:_birth2Label];
    [_birth2Label release];
    
    self.cityLabel = [[UILabel alloc]init];
    [self.bgImageView addSubview:_cityLabel];
    [_cityLabel release];
    
    self.tagsLabel = [[UILabel alloc]init];
    self.tagsLabel.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0];
    [self.bgImageView addSubview:_tagsLabel];
    [_tagsLabel release];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.bgImageView.frame = CGRectMake(0, 0, WIDTH, CHEIGHT * 1.2);
    
    self.photoImageView.frame = CGRectMake(self.bgImageView.frame.size.width / 2 - WIDTH / 10, 44 + 20, WIDTH / 5, WIDTH / 5);
    
    self.nicknameLabel.frame = CGRectMake(0,64 + 20 + 5 + self.photoImageView.frame.size.height, WIDTH, 20);
    self.nicknameLabel.font = [UIFont systemFontOfSize:15];
    
    self.groupsLabel.frame = CGRectMake(0 ,64 + 20 + 10 + self.photoImageView.frame.size.height + self.nicknameLabel.frame.size.height, WIDTH, 20);
    self.groupsLabel.font = [UIFont systemFontOfSize:13];
    
    self.avatarImageView.frame = CGRectMake(10,64 + 10 + self.photoImageView.frame.size.height + self.nicknameLabel.frame.size.height + self.avatarImageView.frame.size.height, WIDTH / 7.5, WIDTH / 7.5);
    
    self.petnameLabel.frame = CGRectMake(10 + self.avatarImageView.frame.size.width + 10 + 20, 64 + 10 + self.photoImageView.frame.size.height + self.photoImageView.frame.size.height, WIDTH / 2, 20);
    self.petnameLabel.font = [UIFont systemFontOfSize:13];

    
    self.birthLabel.frame = CGRectMake(10 + self.avatarImageView.frame.size.width + 10 + 20, 64 + 10 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height , WIDTH / 2, 20);
    self.birthLabel.font = [UIFont systemFontOfSize:13];

    
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(13,64 + 10 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 10, WIDTH - 20, 1)];
    lineLabel.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5];
    [self addSubview:lineLabel];
    [lineLabel release];
    
    self.picnumButton.frame = CGRectMake(5, 64 + 10 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20, CWIDTH / 5, 20);
    self.picnumButton.titleLabel.font = [UIFont systemFontOfSize:13];

    
    self.storynumButton.frame = CGRectMake(5 + self.picnumButton.frame.size.width + 19, 64 + 10 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20, CWIDTH / 5, 20);
    self.storynumButton.titleLabel.font = [UIFont systemFontOfSize:13];
    
    self.fnumButton.frame = CGRectMake(5 + self.picnumButton.frame.size.width + 19  + self.storynumButton.frame.size.width + 19, 64 + 10 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20, CWIDTH / 5, 20);
    self.fnumButton.titleLabel.font = [UIFont systemFontOfSize:13];

    
    self.zanLabel.frame = CGRectMake(5 + self.picnumButton.frame.size.width + 19  + self.storynumButton.frame.size.width + 19 + self.fnumButton.frame.size.width + 19,64 + 10 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20, CWIDTH / 5, 20);
    self.zanLabel.font = [UIFont systemFontOfSize:13];

    NSArray *array = @[@"成长",@"故事",@"伙伴",@"点赞"];
    for (NSInteger i = 0; i < 4; i++) {
        UILabel *label = [[UILabel alloc]init];
        label.frame = CGRectMake(5 + i * WIDTH / 5 + i * 19, 64 + 10 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20 + self.zanLabel.frame.size.height, WIDTH / 5, 20);
        label.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.1];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:13];
        label.text = array[i];
        [self.contentView addSubview:label];
        [label release];
    }
    
    UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 64 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20 + self.zanLabel.frame.size.height + 40, CWIDTH, 40)];
    messageLabel.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.1];
    messageLabel.text = @"    基本资料";
    messageLabel.font = [UIFont systemFontOfSize:15];

    [self addSubview:messageLabel];
    [messageLabel release];
    
    self.type_nameLabel.frame = CGRectMake(0, 64 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20 + self.zanLabel.frame.size.height + 40 + messageLabel.frame.size.height, CWIDTH, 35);
    self.type_nameLabel.font = [UIFont systemFontOfSize:14];


    self.birth2Label.frame = CGRectMake(0, 64 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20 + self.zanLabel.frame.size.height + 40 + messageLabel.frame.size.height + self.type_nameLabel.frame.size.height, CWIDTH, 35);
    self.birth2Label.font = [UIFont systemFontOfSize:14];


    self.cityLabel.frame = CGRectMake(0, 64 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20 + self.zanLabel.frame.size.height + 40 + messageLabel.frame.size.height + self.type_nameLabel.frame.size.height + self.birth2Label.frame.size.height, CWIDTH, 35);
    self.cityLabel.font = [UIFont systemFontOfSize:14];


    UILabel *tag = [[UILabel alloc]initWithFrame:CGRectMake(0, 64 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20 + self.zanLabel.frame.size.height + 40 + messageLabel.frame.size.height + self.type_nameLabel.frame.size.height + self.birth2Label.frame.size.height + self.cityLabel.frame.size.height, CWIDTH, 40)];
    tag.font = [UIFont systemFontOfSize:15];
    tag.text = @"    个性标签";
    tag.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.1];
    [self addSubview:tag];
    [tag release];
    
    self.tagsLabel.frame = CGRectMake(0, 64 + self.photoImageView.frame.size.height * 2 + self.petnameLabel.frame.size.height + self.petnameLabel.frame.size.height + 20 + self.zanLabel.frame.size.height + 40 + messageLabel.frame.size.height + self.type_nameLabel.frame.size.height + self.birth2Label.frame.size.height + self.cityLabel.frame.size.height + tag.frame.size.height, CWIDTH, 35);
    self.tagsLabel.font = [UIFont systemFontOfSize:14];
}

- (void)setDetailOfPhotograph:(DetailOfPhotograph *)detailOfPhotograph{
    if (_detailOfPhotograph != detailOfPhotograph) {
        [_detailOfPhotograph release];
        _detailOfPhotograph = [detailOfPhotograph retain];
    }
    NSURL *avatarImageUrl = [NSURL URLWithString:detailOfPhotograph.info.avatar];
    [self.avatarImageView sd_setImageWithURL:avatarImageUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    [self.photoImageView sd_setImageWithURL:avatarImageUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    self.nicknameLabel.text = [NSString stringWithFormat:@"👤%@", detailOfPhotograph.info.nickname];
    self.nicknameLabel.textAlignment = NSTextAlignmentCenter;

    self.groupsLabel.text = [NSString stringWithFormat:@"S用户 :%@" ,detailOfPhotograph.info.groups];
    self.groupsLabel.textAlignment = NSTextAlignmentCenter;
    
    self.petnameLabel.text = detailOfPhotograph.pets.petname;
    
    self.type_nameLabel.text = [NSString stringWithFormat:@"首次养宠: %@", detailOfPhotograph.pets.type_name];
    self.type_nameLabel.textAlignment = NSTextAlignmentCenter;
    
    [self.picnumButton setTitle:[NSString stringWithFormat:@"%@",detailOfPhotograph.pets.picnum] forState:UIControlStateNormal];
    
    [self.storynumButton setTitle:[NSString stringWithFormat:@"%@",detailOfPhotograph.pets.storynum] forState:UIControlStateNormal];
    
    [self.fnumButton setTitle:[NSString stringWithFormat:@"%@",detailOfPhotograph.pets.fnum] forState:UIControlStateNormal];
    
    self.zanLabel.text = detailOfPhotograph.pets.zan;
    self.zanLabel.textAlignment = NSTextAlignmentCenter;
    
    self.birthLabel.text = detailOfPhotograph.pets.birth;

    self.birth2Label.textAlignment = NSTextAlignmentCenter;
    self.birth2Label.text = [NSString stringWithFormat:@"养宠生日: %@", detailOfPhotograph.pets.birth];

    self.cityLabel.text = [NSString stringWithFormat:@"居住城市: %@", detailOfPhotograph.info.citys];
    self.cityLabel.textAlignment = NSTextAlignmentCenter;

    self.tagsLabel.text = detailOfPhotograph.info.tags;
    self.tagsLabel.numberOfLines = 0;
    self.tagsLabel.textAlignment = NSTextAlignmentCenter;
}

+ (DetailOfPhotographTableViewCell *)detailOfPhotopraphTableViewCellWithTableView:(UITableView *)tableView{
    static NSString *detailOfPhotographTableViewCell = @"detailOfPhotographTableViewCell";
    DetailOfPhotographTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:detailOfPhotographTableViewCell];
    if (!cell) {
        cell = [[[DetailOfPhotographTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:detailOfPhotographTableViewCell] autorelease];
    }
    return cell;
}

- (void)picnumButtonAction:(UIButton *)button{
    [self.delegate pushToPicNumPage:nil];
}

- (void)storynumButtonAction:(UIButton *)button{
    [self.delegate pushToNextPage:nil];
}

- (void)fnumButtonAction:(UIButton *)button{
    [self.delegate pushToFnumPage:nil];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
